<?php
    include_once("../action/checkAuthenticationAction.php");
    include_once("../service/userService.php");
    include_once("../util/constant.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Dashboard</title>
	<?php include("import-css.php");?>	
</head>
<body>
	<?php include("header.php");?>
    
    <div class="container-fluid">
		<div class="row-fluid">
            <!--Menu-->
            <?php include("menu.php");?>
            <!--Content-->
            <?php
                if(!authUtil(array("edit staff","create staff","view staff","delete staff"),$perm_array,true)){
                    echo "<script>window.location.href='../admin/index.php';</script>";
                }
            ?>
            <div class="box span10 offset2">
    					<div class="box-header well" data-original-title>
    						<a class="btn btn-primary" href="./user-detail.php?action=<?php echo NEW_ACTION; ?>">
                                <i class="icon-edit icon-white"></i>Thêm mới
                            </a>
    						<div class="box-icon">
    							<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
    							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
    						</div>
    					</div>
    					<div class="box-content">
    						<table class="table table-striped table-bordered bootstrap-datatable datatable">
    						  <thead>
    							  <tr>
    								  <th>Nhân viên</th>
                                      <th>Họ tên</th>
    								  <th>Nhóm</th>
                                      <th>Quyền</th>
                                      <th>Chức năng</th>
    							  </tr>
    						  </thead>   
    						  <tbody>
								<?php
                                    $users = getAllStaffUser();
                                    while($user = mysql_fetch_array($users)){
                                        $groups = getAllGroupOfUser($user["USER_ID"]);
                                ?>
                                        <tr>
                                            <td><?php echo $user["USER_USERNAME"]; ?></td>
                                            <td><?php echo $user["USER_FULLNAME"]; ?></td>
                                            <td>
                                                <?php
                                                    while($group = mysql_fetch_array($groups)){   
                                                ?>
                                                        [<?php echo $group["ROLE_NAME"]; ?>]
                                                <?php
                                                    }
                                                ?>
                                            </td>
                                            <td>
                                                <?php
                                                        $permissions = getPermissionOfUser($user["USER_ID"]);
                                                        while($permission = mysql_fetch_array($permissions)){
                                                ?>
                                                            [<?php echo $permission["PRI_NAME"]; ?>]
                                                <?php
                                                        }
                                                        echo "<br/>";
                                                ?>
                                            </td>
                                            <td>
                                                <a class="btn btn-info" href="./user-detail.php?action=<?php echo EDIT_ACTION; ?>&id=<?php echo $user['USER_ID']; ?>">
                                                    <i class="icon-edit icon-white"></i>  
                                                    Cập nhật
                                                </a>
                                                <?php
                                                    if ($user["USER_STATUS"]){
                                                ?>
                                                    <a class="btn btn-danger" href="../action/disableStaff.php?id=<?php echo $user['USER_ID']; ?>">
                                                        <i class="icon-edit icon-white"></i>  
                                                        Disable
                                                    </a>
                                                <?php        
                                                    }else{
                                                ?>
                                                    <a class="btn" href="../action/enableStaff.php?id=<?php echo $user['USER_ID']; ?>">
                                                        <i class="icon-edit icon-white"></i>  
                                                        Enable
                                                    </a>    
                                                <?php
                                                    }
                                                ?>
                                                
                                                
                                            </td>
                                        </tr>
                                <?php
                                    }
                                ?>
    						  </tbody>
    					  </table>            
                        </div>
            </div><!--/span-->
        </div>
    </div>

    <?php include("footer.php");?>
		
	</div><!--/.fluid-container-->

	<?php include("import-js.php");?>	
    
</body>
</html>
